package com.lbs.jiepiaisi.base;

import android.content.Context;

import com.lbs.jiepiaisi.utils.DialogUtil;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by yu on 2019/12/16 10:40.
 * Description:
 */

public abstract class ProgressObserver<T extends BaseResponseEntity> extends BaseObserver<T> {
	private Context context;
	private boolean showLoading;

	public ProgressObserver(Context context){
		this(context,true);
	}

	public ProgressObserver(Context context, boolean isShow){
		this.context = context;
		this.showLoading = isShow;
	}

	@Override
	public void onSubscribe(@NonNull Disposable d) {
		if (!d.isDisposed()) {
			if (showLoading) DialogUtil.show(context);
		}
	}

	@Override
	public void onComplete() {
		if (showLoading) DialogUtil.dismiss();
	}

	@Override
	public void onError(@NonNull Throwable e) {
		super.onError(e);
		if (showLoading) DialogUtil.dismiss();
	}


}
